<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div></div>
    <div class="box"></div>
    <script>
        const div = document.querySelector('div')
        // 利用递归 + setTimeout 每隔一秒输出当前时间
        function getTimer() {
            div.innerHTML = new Date().toLocaleString()
            setTimeout(getTimer, 1000)
        }
        const box = document.querySelector('.box')
        getTimer()
        function getTimer2() {
            box.innerHTML = new Date().toLocaleString()
            setTimeout(getTimer2,1000)
        }
        getTimer2()
    </script>
</body>

</html>